/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
 *
 * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
 * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
 *
 * Contributor(s): 
 *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
 *  
 * If you didn't download this code from the following link, you should check
 * if you aren't using an obsolete version: http://www.isqlviewer.com
 */
package org.isqlviewer;

import java.net.URL;
import java.util.Date;

/**
 * Lightweight object to refer to a service definition at runtime.
 * <p>
 * Service definitions within iSQL-Viewer can be and most often are heavy objects containing lots of information
 * regarding how to connect to a specific JDBC resource. This class serves as a lightwieght reference containing only
 * the basic information required to connect to the service, without having all the service connection information
 * resident in memory.
 * <p>
 * 
 * @author Mark A. Kobold &lt;mkobold at isqlviewer dot com&gt;
 * @version 1.0
 */
public class ServiceReference {

    private long id = -1;
    private String name = null;
    private int order = -1;
    private Date lastUsed = null;
    private Date createdOn = null;
    private URL resourceURL = null;

    /**
     * Gets the unique identifier for this service reference.
     * <p>
     * Simply number that unique identifies this service reference within the iSQL-Viewer application. If the Id is -1
     * or less than 0, then that indicates that this particular service reference instance is not registered within the
     * application.
     * <p>
     * This value has no real value other than uniquely identifying this service.
     * 
     * @return the id of this service reference.
     */
    public long getId() {

        return id;
    }

    /**
     * Sets the service reference identifier to the specified value.
     * <p>
     * 
     * @param id the id to set to uniquely identify this service.
     */
    public void setId(long id) {

        this.id = id;
    }

    /**
     * Gets the common service name for this reference.
     * <p>
     * This is the name set by the user when the service definition was created.
     * 
     * @return the name of the service this instance refers to; can be null if not set.
     */
    public String getName() {

        return name;
    }

    /**
     * Sets the service name this instance refers to.
     * <p>
     * 
     * @param name to set as a logical reference for this instance.
     * @throws NullPointerException if the given name is <tt>null</tt>.
     * @throws IllegalArgumentException if the given name is blank.
     */
    public void setName(String name) {

        if (name == null) {
            throw new NullPointerException("name");
        } else if (name.trim().length() == 0) {
            throw new IllegalArgumentException("name cannot be blank");
        }
        this.name = name;
    }

    /**
     * Gets the preferred order of this service.
     * <p>
     * The order refers to the order defined by the user as thier preferred order.
     * 
     * @return the order of this service as determined by the user.
     */
    public int getOrder() {

        return order;
    }

    /**
     * Sets the order of this service reference.
     * <p>
     * 
     * @param order the order to set for this reference.
     * @throws IllegalArgumentException if the given order is less than zero.
     */
    public void setOrder(int order) {

        this.order = order;
    }

    /**
     * Gets the resource URL containing the service information for this instance.
     * <p>
     * This points to the service file containing all the nessecary connection information used to make and configure
     * JDBC connections made by iSQL-Viewer.
     * <p>
     * The idea for using URL versus local file is allow service defintions to be accessed via HTTP and other Java
     * supported protocols.
     * 
     * @return the resource URL containing the detailed service connection information.
     */
    public URL getResourceURL() {

        return resourceURL;
    }

    /**
     * Sets the resource URL for this service reference.
     * <p>
     * 
     * @param resourceURL to set for this reference.
     * @throws NullPointerException if the given URL is null.
     */
    public void setResourceURL(URL resourceURL) {

        this.resourceURL = resourceURL;
    }

    /**
     * Gets the last time a connection was made to the referring service by iSQL-Viewer.
     * <p>
     * 
     * @return the date and time at which a connection was made to this service.
     */
    public Date getLastUsed() {

        return lastUsed;
    }

    /**
     * Sets the last time a connection was made to this service.
     * <p>
     * 
     * @param lastUsed the date and time at which a connection was successfull.
     */
    public void setLastUsed(Date lastUsed) {

        this.lastUsed = lastUsed;
    }

    /**
     * @return the createdOn
     */
    public Date getCreatedOn() {

        return createdOn;
    }

    /**
     * @param createdOn the createdOn to set
     */
    public void setCreatedOn(Date createdOn) {

        this.createdOn = createdOn;
    }
}